package com.tanhua.server.controller;

import com.tanhua.domain.db.Settings;
import com.tanhua.server.service.SettingsService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 通用设置查询
     * 请求链接:GET/users/settings
     * 请求参数:
     *          Authorization
     * 返回值:
     *          SettingsVo对象
     */

    @GetMapping("/settings")
    public ResponseEntity settings(){
        return settingsService.settings();
    }

    /**
     * 设置陌生人问题
     * 请求链接:POST/users/questions
     * 请求参数:
     *          Headers:Authorization
     *          Body:content 不用想就是Json map集合
     * 返回值:
     *          无
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        //1.获取问题内容
        String content= (String) map.get("content");
        //2.调用service
        return settingsService.questions(content);
    }

    /**
     * 通知消息设置保存
     * 请求链接:POST/users/notifications/setting
     * 请求参数:
     *          Headers:Authorization
     *          Body:likeNotification,pinglunNotification,gonggaoNotification
     * 返回值null
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity saveSettings(@RequestBody Settings settings){
        return settingsService.saveSettings(settings);
    }

    /**
     * 黑名单翻页列表
     * 请求链接:GET/users/blacklist
     * 请求参数:
     *          Headers:Headers
     *          Query:page,pagesize  query形式的是 链接后面加上问号 ?page=1&pagesize=10
     * 返回值:
     *          PageResult:其中包含了所有的UserInfo
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize){
        return settingsService.blacklist(page,pagesize);
    }

    /** 想
     * 黑名单移除
     * 请求链接:DELETE/users/blacklist/:uid uid实际是就是被拉黑的用户ID 加上大括号 {blackUserId}
     * 请求参数:
     *          路径参数：uid
     * 返回值Null
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId){
        return settingsService.deleteBlackList(blackUserId);
    }
}
